let uploadConfig = {
  baseUrl: 'https://szsp.suitbim.com.cn:7201/bimv3d',
  uploadUrl: '/rf/:category/file/url/separate/upload',
  mergeUrl: '/rf/:category/file/notify/upload/success',
  uploadModelUrl: '/rf/project/file/url/separate/upload',
  mergeModelFileChunks: '/rf/project/file/notify/upload/success',
  uploadModelTemplateUrl: '/rf/assetmod/file/url/separate/upload',
  mergeModelTemplateChunks: '/rf/assetmod/file/notify/upload/success',
  uploadStaticFileUrl: '/rf/static/file/url/separate/upload',
  mergeStaticFileChunks: '/rf/static/file/notify/upload/success',
  checkTransformStatus: '/data/proj/status/trans',
  getDownloadChunkUrls: '/rf/project/file/download/'
}

export enum ModelTransformStatus {
  // ALL = 0,
  WAITING = 1, // 排队
  PENDING = 2, // 转换工具转换
  SUCCESS = 3, // 转换成功
  FAIL = 4, // 转换失败
  CANCEL = 5, // 转换取消
  WAITING_MERGING = 6, // 文档merge中
  SERVER_TRANSFORMING = 7, // 转换工具转换结束 服务器处理阶段
}

export const SUPPORT_TYPE = [
  'pds',
  'fbx',
  'dwg',
  'rvt',
  'ifc',
  'lbg',
  'rvm',
  'stp',
  'step',
  'skp',
  'zip',
  'rfa',
] // file选择接受的文件类型

export const TRANSFORMATION_CONFIG = {
  enableAtlas: [
    'pds',
    'fbx',
    'dwg',
    'rvt',
    'ifc',
    'lbg',
    'rvm',
    'stp',
    'step',
    'skp',
    'zip',
    'rfa',
  ], // 开启 Atlas 图集
  enableKtx2: [
    'pds',
    'fbx',
    'dwg',
    'rvt',
    'ifc',
    'lbg',
    'rvm',
    'stp',
    'step',
    'skp',
    'zip',
    'rfa',
  ], // 开启 Ktx2 压缩
  enableBorder: [
    'pds',
    'fbx',
    'rvt',
    'ifc',
    'lbg',
    'rvm',
    'stp',
    'step',
    'skp',
    'zip',
    'rfa',
  ], // 开启边界

  enableTransferPlanView: ['rvt'], // 开启平面视图转换
  enableRealistic: ['rvt', 'rfa'], // 开启渲染模式 真实渲染 着色渲染
  enableFilterHidden: ['rvt'], // 开启过滤隐藏
  transViewName: ['rvt', 'rfa'], // 转换视图名称
  transMainFile: ['zip'], // 转换主文件
  enableTransRoom: ['rvt'], // 开启房间
}

export enum GISModelType {
  Satelite = 'IMGTILES', // 卫片
  Oblique = '3DTILES', // 倾斜摄影
  Terrain = 'TERTILES', // 地形 虚构的 这个为了选项可以区分 卫片
}
const GISModelShowNameMap = {
  IMGTILES: 'GIS模型-DOM',
  '3DTILES': 'GIS模型-倾斜摄影',
  TERTILES: 'GIS模型-DEM',
  TILES: 'GIS模型-地形',
}
export const CategoryShowName = [
  '全部类型',
  'BIM模型',
  'GIS模型',
  'FBX模型',
  '矢量图模型',
]
export enum ModelType {
  ALL = 0,
  BIM_MODEL = 1,
  GIS_MODEL = 2,
  FBX_MODEL = 3,
  VEC_MODEL = 4,
}
export enum Category {
  ALL_TYPE = 0,
  BIM_MODEL = 1,
  GIS_MODEL = 2,
  FBX_MODEL = 3,
  VECTOR_MODEL = 4,
}
// Category 和 CategorySubType 一一对应
export const CategorySubType = [
  [],
  ['pds', 'rvt', 'ifc', 'rvm', 'stp', 'step', 'skp', 'rfa'],
  ['gis'],
  ['fbx', 'lbg'],
  ['dwg'],
]
export type SubType =
  | 'pds'
  | 'gis'
  | 'fbx'
  | 'dwg'
  | 'rvt'
  | 'ifc'
  | 'lbg'
  | 'rvm'
  | 'stp'
  | 'step'
  | 'skp'
  | 'rfa'
export const SubTypeToCategoryMap: {
  [key in SubType]: Category
} = {
  pds: Category.BIM_MODEL,
  gis: Category.GIS_MODEL,
  fbx: Category.FBX_MODEL,
  lbg: Category.FBX_MODEL,
  dwg: Category.VECTOR_MODEL,
  rvt: Category.BIM_MODEL,
  ifc: Category.BIM_MODEL,
  rfa: Category.BIM_MODEL,
  rvm: Category.BIM_MODEL,
  stp: Category.BIM_MODEL,
  step: Category.BIM_MODEL,
  skp: Category.BIM_MODEL,
}
export function getCategoryShowName(category: Category) {
  return CategoryShowName[category]
}
export function getCategoryFrom(subType: SubType) {
  return SubTypeToCategoryMap[subType]
}
export function getSubTypesFrom(category: Category) {
  return CategorySubType[category]
}
export function getGISModelShowName(type: GISModelType) {
  return GISModelShowNameMap[type]
}

const getTransformConfig = (subType: SubType) => {
  subType = subType.toLowerCase() as SubType
  if (subType === 'rvt') {
    return {
      enableAtlas: true,
      enableKtx2: true,
      enableBorder: false,
      enableTransferPlanView: false,
      enableRealistic: true,
      enableFilterHidden: true,
      border: 0,
    }
  }
  return {
    enableAtlas: true,
    enableKtx2: true,
    enableBorder: false,
    border: 0,
  }
}

const pwdReg = /^(.{0,5}|.{17,}|[^0-9]*|[a-zA-Z0-9]*)$/
const mobileRule = /(?:^1[3456789]|^9[28])\d{9}$/

const setUploadConfig = (config: Partial<typeof uploadConfig>) => {
  uploadConfig = {
    ...uploadConfig,
    ...config,
  }
}

export { uploadConfig, getTransformConfig, setUploadConfig }
